import {defineStore} from 'pinia';

export const useVepSupplyServiceStore = defineStore('vepSupplyService', {
    state() {
        return {
            // 直接售卖物质产品纯收益（万元/年）
            inDirectProductProfit: 0,
            // 精深加工产品纯收益（万元/年）
            inProcessProfit: 0,
        };
    },
    actions: {
        reset() {
            this.inDirectProductProfit = 0;
            this.inProcessProfit = 0;
        }
    },
    getters: {
        // 计算属性示例
        // outVepSupplyService(): number {
        //     // 物质供给(万元)=（直接售卖物质产品纯收益+精深加工产品纯收益）*8.51356
        //     const result = (this.inDirectProductProfit + this.inProcessProfit)*8.51356;
        //     return Number(result.toFixed(4));
        // },
        outVepSupplyService(): number {
            // 确保值是数字类型
            const directProfit = parseFloat(String(this.inDirectProductProfit)) || 0;
            const processProfit = parseFloat(String(this.inProcessProfit)) || 0;
            const result = (directProfit + processProfit) * 8.51356;
            return Number(result.toFixed(4));
        },
    },
});


export const useVepCulturalServiceStore = defineStore('vepCulturalService', {
    state() {
        return {
            // 旅游康养纯收益（万元/年）
            inTourismHealthcareProfit: 0,
            // 客房数量（间）
            inHotelRooms: 0,
            // 客房价格（元/间）
            inRoomPrice: 0,
            // 年平均入住率（%）
            inOccupancyRate: 0,
            // 商品房租售交易纯收益（万元/年）
            inPropertyProfit: 0,
            // 日客流量（人/天）
            dailyPassengerFlowPeople: 0,
            // 人均日消费（元/人）
            perCapitaDailySpendingYuan: 0,
            // 门票（元/人）
            ticketPricePerPerson: 0,
        };
    },
    actions: {
        reset() {
            this.inTourismHealthcareProfit = 0;
            this.inRoomPrice = 0;
            this.inHotelRooms = 0;
            this.inOccupancyRate = 0;
            this.inPropertyProfit = 0;
            this.inPropertyProfit = 0;
            this.dailyPassengerFlowPeople = 0;
            this.perCapitaDailySpendingYuan = 0;
            this.ticketPricePerPerson = 0;
        }
    },
    getters: {
        // 文化服务（万元）=旅游康养纯收益*8.51356+
        // 客房数量*客房价格*(客房价格/170-1)*年平均入住率*365*20/10000
        // +商品房租售交易纯收益*8.51356
        // +日客流量*人均日消费*365*8.51356/10000  # 门票为0时不算这一行
        outVepCulturalService(): number {
            const result1 = (
                this.inTourismHealthcareProfit * 8.51356 +
                this.inHotelRooms * this.inRoomPrice * (this.inRoomPrice / 170 - 1) * this.inOccupancyRate*0.01 * 365 * 20 / 10000 +
                this.inPropertyProfit * 8.51356 +
                this.dailyPassengerFlowPeople * this.perCapitaDailySpendingYuan * 365 * 8.51356 / 10000
            );
            const result2 = (
                this.inTourismHealthcareProfit * 8.51356 +
                this.inHotelRooms * this.inRoomPrice * (this.inRoomPrice / 170 - 1) * this.inOccupancyRate*0.01 * 365 * 20 / 10000 +
                this.inPropertyProfit * 8.51356
            );
            let result = 0
            if(this.ticketPricePerPerson == 0){
                result = result1;
            }else {
                result = result2;
            }
            return Number(result.toFixed(4));
        },
    },
});


export const useVepRegulationServiceStore = defineStore('vepRegulationService', {
    state() {
        return {
            // 项目占地面积（平方千米）
            inProjectLandArea: 0,
            // 所在行政区面积（km2） projectTownArea
            projectTownArea: 0,
            // 项目所在乡镇调节服务价值
            regionRegulationService: 0,

            labelInProjectLandArea: '占地面积（km2）',
            labelRegionArea: '所在区县面积（km2）',
            labelRegionRegulationService: '所在区县调节服务GEP',
        };
    },
    actions: {
        reset() {
            this.inProjectLandArea = 0;
            this.projectTownArea = 0;
            this.regionRegulationService = 0;
        }
    },
    getters: {
        // 调节服务(万元)=项目占地面积（平方千米）/项目所在乡镇面积（平方千米）*项目所在乡镇调节服务价值(万元)
        outVepRegulationService(): number {
            const result: number = (
                this.inProjectLandArea / this.projectTownArea * this.regionRegulationService
            );
            return Number(result.toFixed(4));
        },
    },
});

import { useHomepageStore } from '@/stores/homepage';
const homepageStore = useHomepageStore();

export const useVepDataStore = defineStore('vepDataStore', {
    state() {
        return {
            vepName: '',
            vepSelectRegion:'',
            vepResultArea: '',
            vepCity: '市',
            vepDistrict: '总计',
            vepTown: '总计',
            // vepYear: new Date().getFullYear() - 1, // 默认值2024,
            // vepYear: homepageStore.year, // 默认值2024,
            vepValue: 0,

            // 是否选择完地址
            isSelected: false,
            // vep数据是否计算成功
            isSubmitted: false,
            count: 0,
            vepRegion: [],
            vepTestValue: 0,
            vepNameAll:[]
        }
    },
    actions: {
        reset() {
            console.log("将vep的设置重置！")
            this.vepName = '';
            // vepSelectRegion应该用不上，vepRegion只能是一个数据的数据，在一定程度上与字符串一样
            this.vepSelectRegion = '';
            this.vepCity = '';
            this.vepDistrict = '';
            this.vepTown = '';
            this.vepValue = 0;
            this.vepRegion = [];
            this.isSubmitted = false;
            this.count = 0;

            const vepRegulationStore = useVepRegulationServiceStore();
            vepRegulationStore.reset(); // 调用 reset 方法
            const vepSupplyServiceStore = useVepSupplyServiceStore();
            vepSupplyServiceStore.reset(); // 调用 reset 方法
            const vepCulturalServiceStore = useVepCulturalServiceStore();
            vepCulturalServiceStore.reset(); // 调用 reset 方法
        },
        resetVEP() {
            console.log("清楚vep的输入框！")
            const vepRegulationStore = useVepRegulationServiceStore();
            vepRegulationStore.reset(); // 调用 reset 方法
            const vepSupplyServiceStore = useVepSupplyServiceStore();
            vepSupplyServiceStore.reset(); // 调用 reset 方法
            const vepCulturalServiceStore = useVepCulturalServiceStore();
            vepCulturalServiceStore.reset(); // 调用 reset 方法
        }
    },
    getters:{
        vepExcelName():string{
            return this.vepRegion + this.vepName;
        },
        vepYear():number{
            return homepageStore.year;
        }
    }
})
